package com.wesley.spbtprovider.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wesley.spbtprovider.entity.Admin;
import com.wesley.spbtprovider.service.AdminService;

/**
 * 
 * PUT:更新 POST：创建 GET：获取 DELETE：删除
 *	
 *
 * 
 * @author wesley.wei
 *
 */
@RestController
@RequestMapping(value = "/admin")
public class AdminController {

	@Autowired
	private AdminService adminService;

	@RequestMapping(value = "/get/{id}")
	public Admin getAdminById(@PathVariable Integer id) {
		return adminService.findOne(id);
	}

	@RequestMapping(value = "/save")
	public Admin save() {
		Admin admin = new Admin();
		admin.setName("admin1");
		admin.setPassword("123456");
		return adminService.save(admin);
	}

	/**
	 * 
	 * @return
	 */
	@RequestMapping(value = "/update")
	public Admin update() {
		Admin admin = new Admin();
		admin.setId(1);
		admin.setName("admin1");
		admin.setPassword("111222");
		return adminService.save(admin);
	}

	@RequestMapping(value = "/delete/{id}")
	public int delete(@PathVariable Integer id) {
		adminService.delete(id);
		return 1;
	}

	@RequestMapping(value = "/getByName/{name}")
	public Admin getByName(@PathVariable String name) {
		return adminService.getByName(name);
	}

	@RequestMapping(value = "/getByIdAndName")
	public Admin getByIdAndName() {
		Integer id = 1;
		String name = "weixin";
		return adminService.getByIdAndName(id, name);
	}

	@RequestMapping(value = "/getByPage")
	public List<Admin> getByPage() {
		Page<Admin> page = adminService.getByPage(1);
		return page.getContent();
	}
}
